﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <div>
    <el-form ref="formRefProcessResults" :model="stateProcessResults.vmModel" label-width="100px">
      <el-row>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_RotueId_FormItem" prop="Entity.RotueId" :label="$t('message.autotrans._Model_ProcessResults_Rotue')">
            <el-select v-model="stateProcessResults.vmModel.Entity.RotueId" clearable>
               <el-option v-for="item in stateProcessResults.AllRotues" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_OpId_FormItem" prop="Entity.OpId" :label="$t('message.autotrans._Model_ProcessResults_Op')">
            <el-select v-model="stateProcessResults.vmModel.Entity.OpId" clearable>
               <el-option v-for="item in stateProcessResults.AllOps" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
            </el-select>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_OpCode_FormItem" prop="Entity.OpCode" :label="$t('message.autotrans._Model_ProcessResults_OpCode')">
            <el-input v-model="stateProcessResults.vmModel.Entity.OpCode" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TagId_FormItem" prop="Entity.TagId" :label="$t('message.autotrans._Model_ProcessResults_TagId')">
            <el-input v-model="stateProcessResults.vmModel.Entity.TagId" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_TagName_FormItem" prop="Entity.TagName" :label="$t('message.autotrans._Model_ProcessResults_TagName')">
            <el-input v-model="stateProcessResults.vmModel.Entity.TagName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_DataName_FormItem" prop="Entity.DataName" :label="$t('message.autotrans._Model_ProcessResults_DataName')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessResults_DataName')}), trigger: 'blur' }]" >
            <el-input v-model="stateProcessResults.vmModel.Entity.DataName" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_Unit_FormItem" prop="Entity.Unit" :label="$t('message.autotrans._Model_ProcessResults_Unit')">
            <el-input v-model="stateProcessResults.vmModel.Entity.Unit" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_UpperLimit_FormItem" prop="Entity.UpperLimit" :label="$t('message.autotrans._Model_ProcessResults_UpperLimit')">
            <el-input v-model="stateProcessResults.vmModel.Entity.UpperLimit" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_LowerLimit_FormItem" prop="Entity.LowerLimit" :label="$t('message.autotrans._Model_ProcessResults_LowerLimit')">
            <el-input v-model="stateProcessResults.vmModel.Entity.LowerLimit" clearable></el-input>
        </el-form-item>

        </el-col>
        <el-col :xs="24" :lg="12" class="mb20">
        <el-form-item ref="Entity_ActiveLimit_FormItem" prop="Entity.ActiveLimit" :label="$t('message.autotrans._Model_ProcessResults_ActiveLimit')"            :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_ProcessResults_ActiveLimit')}), trigger: 'blur' }]" >
            <el-switch v-model="stateProcessResults.vmModel.Entity.ActiveLimit" clearable></el-switch>
        </el-form-item>

        </el-col>
      </el-row>

      <div style="text-align:right;">
        <WtmButton @click="onSubmitProcessResults"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

        <WtmButton @click="onCloseProcessResults"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

      </div>

    </el-form>

  </div>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageProcessManagementProcessResultsEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { processresultsApi } from '/@/api/processmanagement/processresults';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefProcessResults = ref();
const stateProcessResults = reactive({
    vmModel: {
	  Entity:{
        RotueId: null,
        OpId: null,
        OpCode: '',
        TagId: null,
        TagName: '',
        DataName: '',
        Unit: '',
        UpperLimit: null,
        LowerLimit: null,
        ActiveLimit: undefined,
        ID:null,
      },

	},
    
    AllRotues: [] as any[],
    AllOps: [] as any[],
});

// 取消
const onCloseProcessResults = () => {
    closeDialog();
};

// 提交
const onSubmitProcessResults = () => {
 	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});
   formRefProcessResults.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            processresultsApi().edit(stateProcessResults.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};

// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/ProcessManagement/ProcessResults/GetProcessRoutes',[],false).then(x=>{stateProcessResults.AllRotues = x});
    other.getSelectList('/api/ProcessManagement/ProcessResults/GetProcessRouteItems',[],false).then(x=>{stateProcessResults.AllOps = x});
    if (ci.attrs["wtmdata"]) {
		stateProcessResults.vmModel.Entity.ID = ci.attrs["wtmdata"].ID;
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateProcessResults.vmModel.Entity.ID = useRouter().currentRoute.value.query.id as any;
	}
	processresultsApi().get(stateProcessResults.vmModel.Entity.ID ?? "").then((data: any) => other.setValue(stateProcessResults.vmModel, data));
});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

